﻿function uploadProgress() {
    var e = arguments[0] || window.event;
    var src = e.srcElement || e.target;    // src 就是事件的触发源

    var uploadid = src.DiskFileUpload_GUID; // 取得上传的编号

    var dueTime = src.dueTime;
    var period = src.period;
    var callbackFunc = window[src.callbackFunc];

    window.setTimeout(
        function () {
            window.setInterval(
                function () {
                    var xhr;
                    if (window.ActiveXObject)
                        xhr = new ActiveXObject("Microsoft.XMLHTTP");
                    else
                        xhr = new XMLHttpRequest();

                    xhr.onreadystatechange = function () {
                        if (xhr.readyState == 4) {
                            if (xhr.status == 200) {
                                var result = eval("(" + xhr.responseText + ")");
                                callbackFunc(result.percent);
                            }
                        }
                    };

                    xhr.open("get", "progress.ashx?DiskFileUpload_GUID=" + uploadid, false);
                    xhr.send(null);                   
                },
                period
                );
        }
        ,
        dueTime
        );

}